/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class code3 {
    //移除链表元素:法二：傀儡节点
    public ListNode removeElements(ListNode head, int val) {
        if(head == null) {
            return head;
        }

        ListNode retp = new ListNode(0);
        retp.next = head;
        ListNode cur = retp;

        while(head != null) {
            if(head.val == val) {
                cur.next = head.next;
            }else {
                cur = cur.next;
            }
            head = head.next;
        }
        return retp.next;
    }
}